package com.cloudfun.campusshare.common.exception;

import com.cloudfun.campusshare.common.constant.Code;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import lombok.Getter;

/**
 * @author linyangping
 * @date 2019/11/19
 * 基本异常
 */
@Getter
public abstract class BaseException extends RuntimeException {
    private Code code;
    private BaseResult<?> baseResult;

    private BaseException() {
        super();
    }

    public BaseException(Code code) {
        super(code.getMsg());
        this.code = code;
        this.baseResult = BaseResultFactory.produceResult(code, code.getMsg());
    }

    BaseException(Code code, String msg) {
        super(msg);
        this.code = code;
        this.baseResult = BaseResultFactory.produceResult(code, msg);
    }

    public Code getErrorCode(){
        return code;
    }

}
